package com.ruoyi.facilityStatus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.facilityInfo.domain.FacilityInfo;
import com.ruoyi.facilityInfo.domain.Status;
import com.ruoyi.facilityInfo.domain.Type;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.facilityStatus.service.IFacilityStatusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设施状态Controller
 * 
 * @author ruoyi
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/facilityStatus/facilityStatus")
public class FacilityStatusController extends BaseController
{
    @Autowired
    private IFacilityStatusService facilityInfoService;

    /**
     * 查询设施状态列表
     */
    @PreAuthorize("@ss.hasPermi('facilityStatus:facilityStatus:list')")
    @GetMapping("/list")
    public TableDataInfo list(FacilityInfo facilityInfo)
    {
        startPage();
        List<FacilityInfo> list = facilityInfoService.selectFacilityInfoList(facilityInfo);
        for (FacilityInfo info : list){
            Status.changeTostatus(info);
            Type.changeTotype(info);
        }
        return getDataTable(list);
    }


    /**
     * 获取设施状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('facilityStatus:facilityStatus:query')")
    @GetMapping(value = "/{facilityId}")
    public AjaxResult getInfo(@PathVariable("facilityId") Long facilityId)
    {
        FacilityInfo info = facilityInfoService.selectFacilityInfoByFacilityId(facilityId);
        Status.changeTostatus(info);
        Type.changeTotype(info);
        return success(info);
    }


    /**
     * 修改设施状态
     */
    @PreAuthorize("@ss.hasPermi('facilityStatus:facilityStatus:edit')")
    @Log(title = "设施状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FacilityInfo facilityInfo)
    {
        Type.changeTonum(facilityInfo);
        Status.changeTostatus(facilityInfo);
        return toAjax(facilityInfoService.updateFacilityInfo(facilityInfo));
    }

    /**
     * 删除设施状态
     */
    @PreAuthorize("@ss.hasPermi('facilityStatus:facilityStatus:remove')")
    @Log(title = "设施状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilityIds}")
    public AjaxResult remove(@PathVariable Long[] facilityIds)
    {
        return toAjax(facilityInfoService.deleteFacilityInfoByFacilityIds(facilityIds));
    }
}
